// Copyright (c) 2020, Huawei Technologies.All rights reserved.
//
// Licensed under the BSD 3-Clause License  (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ATen/native/npu/utils/OpAdapter.h"

namespace at {
namespace native {
using namespace at::native::npu;

namespace {
Tensor fast_gelu_npu_nocheck(Tensor& result, const Tensor& self) {
    OpCommand cmd;
    cmd.Name("FastGelu")
        .Input(self)
        .Output(result)
        .Run();

    return result;
}

} // namespace

Tensor fast_gelu_npu(const Tensor& self) {
    auto outputSize = input_same_output_size(self);
    Tensor result = OpPreparation::ApplyTensor(self, outputSize);
    fast_gelu_npu_nocheck(result, self);

    return result;
}

TORCH_LIBRARY_IMPL(aten, NPU, m){
  m.impl("fast_gelu", TORCH_FN(fast_gelu_npu));
}

} // namespace native
} // namespace at

